package com.zhuss.core.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.core.db.dao.ext.UserDeptDao;
import com.zhuss.core.db.entity.UserDept;

/**
 * 查询用户、部门关系 processor
 * @Author: zhushanshuo
 * @Date: 2020/02/11 12:20
 */
@Component("userDeptRead")
public class UserDeptRead {
	
	@Autowired
	private UserDeptDao userDeptDao;
	
	/**
	 * 根据用户查询部门列表
	 * @param userId
	 * @return
	 */
	public Object listDeptId(Long userId) {
		List<UserDept> deptList = userDeptDao.listDept(userId);
		List<Long> deptIdList = new ArrayList<Long>();
		transferDept(deptList, deptIdList);
		return deptIdList;
	}
	
	private void transferDept(List<UserDept> deptList,
			List<Long> deptIdList) {
		for (UserDept item : deptList) {
			deptIdList.add(item.getDeptId());
		}
		
	}

	/**
	 * 根据部门查询用户列表
	 * @param userId
	 * @return
	 */
	public Object listUserId(Long deptId) {
		List<UserDept> userList = userDeptDao.listUser(deptId);
		List<Long> userIdList = new ArrayList<Long>();
		transferUser(userList, userIdList);
		return userIdList;
	}

	private void transferUser(List<UserDept> userList,
			List<Long> userIdList) {
		for (UserDept item : userList) {
			userIdList.add(item.getUserId());
		}
		
	}
	
	

}
